/* 
 * File:   LoggerManager.cpp
 * Author: Gab'z
 * 
 * Created on 8 juin 2012, 13:52
 */

#include <fstream>
#include <iostream>
#include "LoggerManager.h"

namespace calculator {

    LoggerManager* LoggerManager::instance = 0;

    LoggerManager* LoggerManager::getInstance() {
        if (instance == 0) {
            instance = new LoggerManager();
        }
        return instance;
    }

    void LoggerManager::deleteInstance() {
        delete instance;
    }

    LoggerManager::LoggerManager() {

    }

    LoggerManager::~LoggerManager() {
        for (std::map<const std::string, Logger * const>::iterator it = _loggers.begin();
                it != _loggers.end();
                it++) {
            delete it->second;
        }
        _loggers.clear();
        std::cout << "Loggers destroyed";
        std::cout.flush();
    }

    Logger* LoggerManager::getLogger(const std::string& classname) {
        std::map<const std::string, Logger * const>::iterator it = _loggers.find(classname);
        if (it == _loggers.end()) {
            // créer le logger
            Logger* logger = new Logger(classname);
            std::pair<const std::string, Logger * const> paire(classname, logger);
            _loggers.insert(paire);
            return logger;
        }
        // retourner le logger
        return (*it).second;
    }

}